package com.twoGroup.boot.service.imp;


import com.twoGroup.boot.mapper.OrderMapper;
import com.twoGroup.boot.pojo.CartAndShopAndUserAndGoods;
import com.twoGroup.boot.pojo.Order;
import com.twoGroup.boot.pojo.OrderAndAddress;
import com.twoGroup.boot.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    private static Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Transactional
    @Override
    public int addOrder(Order order) {
        return orderMapper.addOrder(order);
    }

    @Transactional
    @Override
    public int deleteOrderY(Integer buyerId, Integer goodsId, String orderNo) {
        return orderMapper.deleteOrderY(buyerId, goodsId, orderNo);
    }

    @Transactional
    @Override
    public int deleteOrderN(Integer buyerId, Integer goodsId, String orderNo) {
        return orderMapper.deleteOrderN(buyerId, goodsId, orderNo);
    }

    @Transactional
    @Override
    public int deleteAllOrderY(Integer buyerId) {
        return orderMapper.deleteAllOrderY(buyerId);
    }

    @Transactional
    @Override
    public int deleteAllOrderN(Integer buyerId) {
        return orderMapper.deleteAllOrderN(buyerId);
    }

    @Transactional
    @Override
    public List<OrderAndAddress> queryAllOrderY(Integer buyerId) {
        List<OrderAndAddress>  list = orderMapper.queryAllOrderY(buyerId);
        for (OrderAndAddress orderAndAddress : list) {
            logger.info(String.valueOf(orderAndAddress));
        }
        return orderMapper.queryAllOrderY(buyerId);
    }

    @Transactional
    @Override
    public List<OrderAndAddress> queryAllOrderN(Integer buyerId) {
        List<OrderAndAddress> orders = orderMapper.queryAllOrderN(buyerId);
        for (OrderAndAddress order : orders) {
            logger.info(String.valueOf(order));
        }
        return orderMapper.queryAllOrderN(buyerId);
    }

    @Transactional
    @Override
    public List<OrderAndAddress> queryByOrder(String orderNo) {
        return orderMapper.queryByOrder(orderNo);
    }

    @Transactional
    @Override
    public Integer queryShopId(Integer shopId) {
        return orderMapper.queryShopId(shopId);
    }

    @Transactional
    @Override
    public Order queryId(Integer buyerId, Integer goodsId, String orderNo) {
        return orderMapper.queryId(buyerId, goodsId, orderNo);
    }

    @Transactional
    @Override
    public int applySuccess(Integer userId, Integer goodsId, String orderNo) {
        return orderMapper.applySuccess(userId, goodsId, orderNo);
    }

    @Override
    public List<CartAndShopAndUserAndGoods> queryUserCart(Integer userId) {
        return orderMapper.queryUserCart(userId);
    }

    @Override
    public OrderAndAddress queryInfAndAddress(String orderNo) {
        return orderMapper.queryInfAndAddress(orderNo);
    }

    @Override
    public Integer queryAllOrderCountY(Integer userId) {
        return orderMapper.queryAllOrderCountY(userId);
    }

    @Override
    public Integer queryAllOrderCountN(Integer userId) {
        return orderMapper.queryAllOrderCountN(userId);
    }


}
